Learn R Programming

Rfast (version 1.2)

Mahalanobis distance: Mahalanobis distance

Description

Mahalanobis distance.

Usage

mahala(x, mu, sigma, ncores, ischol)

Arguments

x
A matrix with the data, where rows denotes observations (vectors) and the columns contain the variables.
mu
The mean vector.
sigma
The covariance or any square symmetric matrix.
ncores
The numbers of cores to use
ischol
A boolean variable set to true if the Cholesky decomposition of the covariance matrix is supplied in the argument "sigma".

Value

A vector with the Mahalanobis distances.

Examples

Run this code
x <- matrix( rnorm(10000 * 200), ncol = 200 )
m <- colMeans(x)
s <- cov(x)
system.time( mahala(x, m, s) )
system.time( mahalanobis(x, m, s) )
a1 <- mahalanobis(x, m, s)
a2 <- mahala(x, m, s)
all.equal(a1, a2)

Run the code above in your browser using DataLab